package com.estagio.entity;


import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table (name="compra")
public class Compra extends NotaFiscal {
	
	@Id
	@SequenceGenerator(name="compra_id", sequenceName="compra_id_seq",allocationSize=1,initialValue = 1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="compra_id" )
	private Integer idCompra;
	
	@JoinColumn(name="idFornecedor")
	@ManyToOne
	private Fornecedor fornecedor;
	
	@OneToMany(cascade=CascadeType.ALL, mappedBy="compra", fetch = FetchType.EAGER)
	@Fetch(FetchMode.SUBSELECT)
	private List<ItemCompra> listaItemCompra;	
	
	
	public Integer getIdCompra() {
		return idCompra;
	}
	public void setIdCompra(Integer idCompra) {
		this.idCompra = idCompra;
	}

	public Fornecedor getFornecedor() {
		return fornecedor;
	}
	public void setFornecedor(Fornecedor fornecedor) {
		this.fornecedor = fornecedor;	
	}
	public List<ItemCompra> getListaItemCompra() {
		return listaItemCompra;
	}
	public void setListaItemCompra(List<ItemCompra> listaItemCompra) {
		this.listaItemCompra = listaItemCompra;
	}

}
